package com.example.a2105_ivideo.test_mvi

import androidx.lifecycle.viewModelScope
import com.example.lib_mvi.base.BaseViewMode
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch

/**
 * @author yaotianxue
 * @description
 * @date 2025/2/24
 */
class MyViewModel:BaseViewMode<MyIntent>() {
    private val bannerDataStateFlow = MutableStateFlow<MyState>(MyState.Loading)
    val bannerDataStateFlow_ = bannerDataStateFlow.asStateFlow()

    /**
     * 根据不同的意图完成不同的处理
     */
    override fun handleIntent() {
        viewModelScope.launch {
            intents.consumeAsFlow().collect{
                when(it){
                    is MyIntent.GetBannerData ->{ getBannerData()}
                    is MyIntent.GetVideoData -> { getVideoData(it)}
                }

            }
        }
    }

    fun getBannerData(){
        viewModelScope.launch {
            //网络请求更新状态流
            bannerDataStateFlow.value = MyState.Success("数据。。。。。。")
        }
    }

    fun getVideoData(intent:MyIntent.GetVideoData){

    }
}